package com.cnhis.cloudhealth.clinical.clidoctor.clicollectfee.bo;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cnhis.cloudhealth.clinical.clidoctor.clicollectfee.dao.CliCollectFeeDao;
import com.cnhis.cloudhealth.clinical.clidoctor.cliparamter.dao.CliParamterDao;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.utils.DateUtils;
import java.util.HashMap;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;

@Service
public class CliCollectFeeBo {
	@Resource
	private CliCollectFeeDao cliCollectFeeDao;
	@Resource
	private CliParamterDao cliParamterDao;
	@SuppressWarnings("unchecked")
	public ModelVo queryCollectFeeItem(Map map)throws Exception{
		ModelVo mo = new ModelVo();
		List list =null;
		Object lDate =map.get("lDate");
		try {
			if(lDate==null||"".equals(lDate.toString())){
				map.put("lDate", DateUtils.getDateStr(new Date())+" 23:59:59");
			}else{
				map.put("lDate", lDate+" 23:59:59");
			}
			list=cliCollectFeeDao.queryCollectFeeItem(map);
			
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
	}
	private List collectFeeItemParamno1(Map map)throws Exception{
		return cliCollectFeeDao.collectFeeItemParamno1(map);
	}
	private List collectFeeItemParamno(Map map)throws Exception{
		return cliCollectFeeDao.collectFeeItemParamno(map);
	}
	@SuppressWarnings("unchecked")
	public ModelVo collectFeeItemDetail(Map map)throws Exception{
		ModelVo mo = new ModelVo();
		List list =null;
		Object lDate =map.get("lDate");
		try {
			if(lDate==null||"".equals(lDate.toString())){
				map.put("lDate", DateUtils.getDateStr(new Date())+" 23:59:59");
			}else{
				map.put("lDate", lDate+" 23:59:59");
			}
			HashMap hs = new HashMap();
			hs.put("productId",9999);
			hs.put("programId",9999);
			hs.put("paramNo", 15);
			String aParamno = cliParamterDao.getSysParamValue(hs);
			if(!"1".equals(aParamno)){
				list = collectFeeItemParamno1(map);
			}else{
				list = collectFeeItemParamno(map);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
	}
	@SuppressWarnings("unchecked")
	public ModelVo chargeDetail(Map map)throws Exception{
		ModelVo mo = new ModelVo();
		List list =null;
		Object lDate =map.get("lDate");
		try {
			if(lDate==null||"".equals(lDate.toString())){
				map.put("lDate", DateUtils.getDateStr(new Date())+" 23:59:59");
			}else{
				map.put("lDate", lDate+" 23:59:59");
			}
			list=cliCollectFeeDao.chargeDetail(map);
			
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
	}
	public ModelVo allFeeItem()throws Exception{
		ModelVo mo = new ModelVo();
		List list =null;
		try {
			list=cliCollectFeeDao.allFeeItem();
			
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
	}
}
